package com.alingrad.android.test.cyborghuman;

import javax.microedition.khronos.opengles.GL10;

import com.alingrad.android.froyoengine.Game;
import com.alingrad.android.froyoengine.GameRenderer;
import com.alingrad.android.froyoengine.input.TouchState;
import com.alingrad.android.froyoengine.tree.TreeNode;

public class VirtualJoypad extends TreeNode {
	
	public static VirtualJoypad sJoypad = new VirtualJoypad();
	
	public static VirtualJoypad get() {
		return sJoypad;
	}
	
	public boolean mAPressed;
	public boolean mLeftPressed;
	public boolean mRightPressed;
	
	public VirtualJoypad() {
		super();
	}
	
	@Override
	public void load(GL10 gl) {
	}

	@Override
	public void update(long delta) {
		mAPressed = false;
		mLeftPressed = false;
		mRightPressed = false;
		for (int i = 0; i < 4; i++) {
			TouchState state = Game.sInputManager.getTouchState(i);
			if (state.isActive()) {
				if (state.mY > GameRenderer.VIEW_HEIGHT / 2) {
					mAPressed = true;
				} else if (state.mX > GameRenderer.VIEW_WIDTH / 2) {
					mRightPressed = true;
				} else if (state.mX < GameRenderer.VIEW_WIDTH / 2) {
					mLeftPressed = true;
				}
			}
		}
	}

	@Override
	public boolean isAlive() {
		return true;
	}

}
